package com.sxt.retry.controller;

import org.springframework.retry.annotation.Retryable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.annotation.Backoff;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sxt.retry.service.RetryService;

import lombok.extern.slf4j.Slf4j;


@Slf4j
@Controller
@RequestMapping("/retry") 
public class TestController {
	
	@Autowired
    private RetryService retryService;
	
	@GetMapping(value = "test0")
    @Retryable(value = {Exception.class},maxAttempts = 4, backoff = @Backoff(delay = 1000,multiplier = 1))
    public String retry0() throws Exception {
		log.info("测试重试机制");
		throw new Exception("异常");
    }
	
	
	@GetMapping(value = "test1")
	public void retry1() {
        int count = retryService.retry(-1);
        System.out.println("库存为 ：" + count);
    }
	
}
